package com.auth.manager.web.sys;

import com.auth.manager.common.resp.Result;
import com.auth.manager.pojo.sys.SysMenu;
import com.auth.manager.pojo.sys.TreeMenu;
import com.auth.manager.service.sys.SysMenuService;
import com.auth.manager.utils.page.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @version 1.0.0
 * @Date: 2022/4/28 20:55
 * @Author ZhuYouBin
 * @Description 系统权限
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @PostMapping("/create")
    public Result create(@RequestBody @Valid SysMenu sysMenu) {
        sysMenuService.createMenu(sysMenu);
        return Result.success("新增成功");
    }

    @GetMapping("/delete/{mid}")
    public Result remove(@PathVariable String mid) {
        sysMenuService.removeMenu(mid);
        return Result.success("删除成功");
    }

    @PostMapping("/update")
    public Result update(@RequestBody @Valid SysMenu sysMenu) {
        sysMenuService.updateMenu(sysMenu);
        return Result.success("更新成功");
    }

    @GetMapping("/queryPage")
    public Result queryPage(SysMenu sysMenu, PageVo pageVo) {
        PageVo queryPage = sysMenuService.queryPage(sysMenu, pageVo);
        return Result.success("查询成功").setData(queryPage);
    }

    @GetMapping("/tree")
    public Result queryTreeMenu(SysMenu sysMenu) {
        List<TreeMenu> treeMenuList = sysMenuService.queryTreeMenu();
        return Result.success("查询成功").setData(treeMenuList);
    }

    @GetMapping("/getRoleMenu/{rid}")
    public Result getRoleMenu(@PathVariable String rid) {
        List<SysMenu> list = sysMenuService.queryRoleMenuByRid(rid);
        return Result.success("查询成功").setData(list);
    }

    @GetMapping("/getUserMenu/{username}")
    public Result getUserMenu(@PathVariable String username) {
        List<TreeMenu> list = sysMenuService.getUserMenu(username);
        return Result.success("查询成功").setData(list);
    }

}
